<?php

include $_SERVER['DOCUMENT_ROOT'].'/online-system/freenew/model/WeiInfo.class.php';
include $_SERVER['DOCUMENT_ROOT'].'/online-system/freenew/model/ToDatabase.class.php';
include $_SERVER['DOCUMENT_ROOT'].'/online-system/freenew/controller/Controller.php';

$route = isset($_GET['route']) ? htmlspecialchars($_GET['route']) : '';

$openid;
$WI = new WeiInfo();
$openid = $WI->getOpenId();

if($openid == "getfalse"){
//var_dump(openid);
	//$openid ="os9qxtydN4HgcBTBX9AStCkvpOiU";
	//setcookie("openid",$openid,time()+7200);
}else{
	setcookie("openid",$openid,time()+7200);
}

if($route == "reserve"){
	
	if($openid == "getfalse"){
	$openid = $_COOKIE["openid"];
	}
	//var_dump($openid);
	//$openid = "os9qxtydN4HgcBTBX9AStCkvpOiU";
	$TD = new ToDatabase();
	$member = $TD->queryById($openid);
	
	if(empty($member['phone'])){
		
		$data = array();
		$SN = $_SERVER['SERVER_NAME'];
		//var_dump($SN);
		
		date_default_timezone_set("PRC");
		$data["DA"] = date("Y-m-d");
		$TI = strtotime("+4 hour");
		$data["R_TI"] = date("H:i",$TI);
	
		//0或其他操作码需要注册
		//$member["operation"] = 0;
		$C = new Controller();
		$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/reserveGuest.php";
		$data['say'] = "尊贵的会员，您好，";
		$C->view($file,$data);
		
	}else{
		//free字段不为0 ，表示有记录，不增送
		if($member["free"] >= 1){
			
			$member["say"] = "你本季新菜已赠送过一次，感谢您的参与，下一季新菜推出时，期待您的参与";
			
			$data = array();
			$SN = $_SERVER['SERVER_NAME'];
			//var_dump($SN);
			
			date_default_timezone_set("PRC");
			$data["DA"] = date("Y-m-d");
			$TI = strtotime("+4 hour");
			$data["R_TI"] = date("H:i",$TI);
			
			//操作码为2代表已经赠送过
			$member["operation"] = 2;
			
			$C = new Controller();
			$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/reserveFreed.php";
			$data['phone'] = $member['phone'];
			$data['name'] = $member['name'];
			$data['say'] = "尊贵的会员，您好，";
			$C->view($file,$data);
			
		}else{
			
			$member["say"] = "下面请选择您的专属免费新菜一份，选择桌号即可赠送";
			
			$data = array();
			$SN = $_SERVER['SERVER_NAME'];
			//var_dump($SN);
			
			date_default_timezone_set("PRC");
			$data["DA"] = date("Y-m-d");
			$TI = strtotime("+4 hour");
			$data["R_TI"] = date("H:i",$TI);
			
			//操作码为1代表可以赠送
			$member["operation"] = 1;
			$data['phone'] = $member['phone'];
			$data['name'] = $member['name'];
			
			$C = new Controller();
			$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/reserve.php";
			$data['phone'] = $member['phone'];
			$data['name'] = $member['name'];
			$C->view($file,$data);
			
		}
		
		
	}

	
	
}else if($route == "register"){
	
	$C = new Controller();
	$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/register.php";
	//$url = "";
	$data = null;
	$C->view($file,$data);
	
	
}else if($route == "freenewdish"){
	
	$member = array();
	$openid = $_COOKIE["openid"];
	
	//$openid = "os9qxtydN4HgcBTBX9AStCkvpOiU";
	$TD = new ToDatabase();
	$member = $TD->queryById($openid);
	

	if(empty($member['phone'])){
		$member["say"] = "您还不是会员或会员未绑定到微信";
		//0或其他操作码需要注册
		$member["operation"] = 0;
		
		$C = new Controller();
		$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/register.php";
		$data = array();
		//var_dump($data);
		$C->view($file,$data);
		
	}else{
		//free字段不为0 ，表示有记录，不增送
		if($member["free"] >= 1){
			
			$member["say"] = "你本季新菜已赠送过一次，感谢您的参与，下一季新菜推出时，期待您的参与";
			
			//操作码为2代表已经赠送过
			$member["operation"] = 2;
			
				//操作码为1代表可以赠送
			$member["operation"] = 1;
			$C = new Controller();
			$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/freeNewDishFreed.php";
			$data['phone'] = $member['phone'];
			$data['name'] = $member['name'];
			$data['operation'] = $member['operation'];
			$data['say'] = "尊贵的会员，您好，";
			//var_dump($data);
			$C->view($file,$data);
			
		}else{
			
			
			//操作码为1代表可以赠送
			$member["operation"] = 1;
			$C = new Controller();
			$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/freeNewDish.php";
			$data['phone'] = $member['phone'];
			$data['name'] = $member['name'];
			$data['operation'] = $member['operation'];
			$data['say'] = "尊贵的会员，您好，";
			//var_dump($data);
			$C->view($file,$data);
			
		}
		
	}
}else if($route == "mi"){
	
	$C = new Controller();
		$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/mi.php";
		$data = array();
		//var_dump($data);
		$C->view($file,$data);
	
}else if($route == "reserve2"){
	$data = array();
	$SN = $_SERVER['SERVER_NAME'];
	//var_dump($SN);
	
	date_default_timezone_set("PRC");
	$data["DA"] = date("Y-m-d");
	$TI = strtotime("+4 hour");
	$data["R_TI"] = date("H:i",$TI);
	
	$C = new Controller();
	$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/reserve2.php";
	
		//var_dump($data);
	$C->view($file,$data);	
	
	
}else if($route == "reservesuccess"){
	
	if($openid == "getfalse"){
	$openid = $_COOKIE["openid"];
	}
	
	
	$TD = new ToDatabase();
	$member = $TD->queryById($openid);
	$reservations = $TD->queryReservationById($openid);
	//var_dump($reservations);
	$data["reservations"] = $reservations;
	$data["name"] = $member["name"];
	$data["phone"] = $member["phone"];
	
	$C = new Controller();
		$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/reservesuccess.php";
		//var_dump($data);
		$C->view($file,$data);
	
	
}else if($route == "getdishsuccess"){
	
	if($openid == "getfalse"){
	$openid = $_COOKIE["openid"];
	}
	
	
	$TD = new ToDatabase();
	$member = $TD->queryById($openid);
	$dishs = $TD->queryDishsById($openid);
	//var_dump($reservations);
	$data["dishs"] = $dishs;
	$data["name"] = $member["name"];
	$data["phone"] = $member["phone"];
	
	$C = new Controller();
		$file = $_SERVER['DOCUMENT_ROOT']."/online-system/freenew/view/getDishSuccess.php";
		//var_dump($data);
		$C->view($file,$data);
	
	
}else {
	
}




?>